const Hapi = require('hapi');

require('env2')('./.env');

const config = require('./config')
// 路由
const routesTest = require('./routes/test')
const routesShop = require('./routes/shops')
const routesOrder = require('./routes/orders')
const routesHello = require('./routes/hello')

// swagger 插件
const pluginHapiSwagger = require('./plugins/hapi-swagger');


const server = new Hapi.Server();

// 配置 服务器个端口
server.connection({
  port: config.port,
  host: config.host
})

const init = async () => {

  await server.register([
    ...pluginHapiSwagger,
  ]);

  server.route([

    ...routesTest,
    ...routesShop,
    ...routesOrder,
    ...routesHello
  ])

  // 启动服务器
  await server.start()
  console.log(`Server Runing At: ${server.info.uri}`);

}

init();